package com.lunhui.monster.provider.impl;

import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.fastjson.JSONObject;
import com.lunhui.monster.business.MonsterService;
import com.lunhui.monster.client.MonsterClient;
import com.lunhui.monster.client.dto.MonsterDto;
import com.lunhui.monster.dal.model.Monster;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * @author renminghe-kg
 */
@Service
public class MonsterClientImpl implements MonsterClient {
    private static final Logger logger = LoggerFactory.getLogger(MonsterClientImpl.class);

    @Autowired
    @Qualifier("monsterService")
    private MonsterService monsterService;

    @Override
    public List<MonsterDto> getMonsterListInfo(int areaId, int sceneId) throws RuntimeException {
        List<MonsterDto> monsterDtoList = new ArrayList<>();

        try
        {

            List<Monster> monsterInfo = monsterService.getMonsterListInfo(areaId, sceneId);

            if (monsterInfo != null) {

                monsterInfo.forEach((entity) -> {
                    MonsterDto monsterDto = new MonsterDto();
                    BeanUtils.copyProperties(entity, monsterDto);

                    monsterDtoList.add(monsterDto);
                });

            }

        } catch (Exception e) {
            logger.error("获取怪物列表信息失败: " + e.getMessage());
        }

        logger.info("地图信息: " + JSONObject.toJSONString(monsterDtoList));

        return monsterDtoList;
    }
}